package utils

import "sync"

type SafeMap struct {
	mu   sync.Mutex
	data map[string]int64
}

func NewSafeMap() *SafeMap {
	return &SafeMap{
		data: make(map[string]int64, 0),
	}
}

func (sm *SafeMap) Put(key string, value int64) {
	sm.mu.Lock()
	defer sm.mu.Unlock()

	sm.data[key] = value
}

func (sm *SafeMap) Get(key string) (int64, bool) {
	sm.mu.Lock()
	defer sm.mu.Unlock()

	val, ok := sm.data[key]
	return val, ok
}

func (sm *SafeMap) Delete(key string) {
	sm.mu.Lock()
	defer sm.mu.Unlock()

	delete(sm.data, key)
}
